package com.reminiscence.main;

import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.reminiscence.classes.Utente;

public class ProfiloAmico extends Activity implements OnClickListener
{

	public static Utente amico = new Utente();
	
	TextView txtNome;
	TextView txtCognome;
	TextView txtData;
	TextView txtSitSent;
	TextView txtEMail;
	TextView txtCittà;
	TextView txtResidenza;
	TextView txtProfPass;
	TextView txtProfAtt;
	ImageView imgFoto;
	
	Button btnVisStorie;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.profilo_amico);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		
		Bundle extras = getIntent().getExtras();
		amico.nomeUtente = extras.getString("IdUtente");
		
		txtNome = (TextView)findViewById(R.id.txtPANome);
		txtCognome = (TextView)findViewById(R.id.txtPCCognome);
		txtData = (TextView)findViewById(R.id.txtDataUt);
		txtSitSent = (TextView)findViewById(R.id.txtSitSenUt);
		txtEMail = (TextView)findViewById(R.id.txtPCEMailUt);
		txtCittà = (TextView)findViewById(R.id.txtNatoAUt);
		txtResidenza = (TextView)findViewById(R.id.txtResidenzaUt);
		txtProfPass = (TextView)findViewById(R.id.txtProfPrincUt);
		txtProfAtt = (TextView)findViewById(R.id.txtProfAtUt);
		imgFoto = (ImageView)findViewById(R.id.imgFoto);;
		
		btnVisStorie = (Button)findViewById(R.id.btnVisualizzaStorie);
		btnVisStorie.setOnClickListener(this);
		
		amico.leggiUtenteA(this);
		txtNome.setText(amico.nome);
		txtCognome.setText(amico.cognome);
		txtData.setText(amico.dataN);
		txtSitSent.setText(amico.statoCivile);
		txtEMail.setText(amico.eMail);
		txtCittà.setText(amico.luogoN);
		txtResidenza.setText(amico.residenza);
		txtProfPass.setText(amico.profPrinc);
		txtProfAtt.setText(amico.profAt);
		
		String nomeFoto = amico.nome + "." + amico.cognome + ".jpg"; 
		System.out.println("ftp://a4151578:Progetto1@remin.site90.com/public_html/foto/"+nomeFoto);
		new DownloadImageTask(imgFoto).execute("ftp://a4151578:Progetto1@remin.site90.com/public_html/foto/" + nomeFoto);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.profilo_amico, menu);
		return true;
	}
	
	
	@Override
	public void onClick(View arg0)
	{
		
	}
	
	private class DownloadImageTask extends AsyncTask<String, Void, Bitmap>
	{
		ImageView bmImage;

		public DownloadImageTask(ImageView bmImage) {
		    this.bmImage = bmImage;
		}

		protected Bitmap doInBackground(String... urls) {
		    String urldisplay = urls[0];
		    Bitmap mIcon11 = null;
		    try {
		        InputStream in = new java.net.URL(urldisplay).openStream();
		        mIcon11 = BitmapFactory.decodeStream(in);
		    } catch (Exception e) {
		        Log.e("Error", e.getMessage());
		        e.printStackTrace();
		    }
		    return mIcon11;
		}

		protected void onPostExecute(Bitmap result)
		{
		    bmImage.setImageBitmap(result);
		}
	}

}
